﻿using System;
using System.Diagnostics;
using Microsoft.CTS.HSG;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Lib.UnitTest
{
    
    
    /// <summary>
    ///This is a test class for SqlScripterDiagnosticsTest and is intended
    ///to contain all SqlScripterDiagnosticsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SqlScripterDiagnosticsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return this.testContextInstance;
            }
            set
            {
                this.testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod]
        public void CreateSqlScripterDiagnosticsInstance()
        {
            SqlScripterDiagnostics s = new SqlScripterDiagnostics();
            Assert.IsNotNull(s);
            Assert.IsNotNull(SqlScripterDiagnostics.ScriptEngineTraceSwitch);
            Assert.IsNotNull(SqlScripterDiagnostics.globalTraceSwitch);
        }

        [TestMethod]
        public void CreateSqlScripterDiagnosticsInstanceWithGlobalTraceSwitch()
        {
            TraceSwitch traceSwitch = new TraceSwitch(
                "CreateSqlScripterDiagnosticsInstanceWithGlobalTraceSwitch",
                "TraceSwitch for CreateSqlScripterDiagnosticsInstanceWithGlobalTraceSwitch unit test"
                );

            SqlScripterDiagnostics s = new SqlScripterDiagnostics(
                traceSwitch
                );

            Assert.IsNotNull(s);
            Assert.IsNotNull(SqlScripterDiagnostics.ScriptEngineTraceSwitch);
            
            Assert.AreEqual<TraceSwitch>(
                traceSwitch,
                SqlScripterDiagnostics.globalTraceSwitch
                );
           
        }

        [TestMethod]
        public void VerifyDefaultTraceLevel()
        {
            SqlScripterDiagnostics s = new SqlScripterDiagnostics();
            
            Assert.AreEqual(
                TraceLevel.Verbose,
                SqlScripterDiagnostics.ScriptEngineTraceSwitch.Level
                );

        }

        [TestMethod]
        public void LogMessageWithStringUsingGlobalSwitch()
        {
            TraceSwitch traceSwitch = new TraceSwitch(
                "CreateSqlScripterDiagnosticsInstanceWithGlobalTraceSwitch",
                "TraceSwitch for CreateSqlScripterDiagnosticsInstanceWithGlobalTraceSwitch unit test"
                );

            traceSwitch.Level = TraceLevel.Verbose;

            SqlScripterDiagnostics s = new SqlScripterDiagnostics(
                traceSwitch
                );

           
            SqlScripterDiagnostics.Log(
                TraceLevel.Info,
                "LogMessageWithString:Info",
                null
                );
        }

        [TestMethod]
        public void LogMessageWithStringUsingDefaultSwitch()
        {
            SqlScripterDiagnostics s = new SqlScripterDiagnostics();
            SqlScripterDiagnostics.ScriptEngineTraceSwitch.Level = TraceLevel.Verbose;

            SqlScripterDiagnostics.Log(
                TraceLevel.Verbose,
                "LogMessageWithString:Verbose",
                null
                );
        }

        [TestMethod]
        public void LogMessageWithStringAndParamsUsingDefaultSwitch()
        {
            SqlScripterDiagnostics s = new SqlScripterDiagnostics();
            SqlScripterDiagnostics.ScriptEngineTraceSwitch.Level = TraceLevel.Verbose;

            SqlScripterDiagnostics.Log(
                TraceLevel.Verbose,
                "LogMessageWithString:Verbose:{0}",
                DateTime.Now.ToString()
                );
        }

        [TestMethod]
        public void LogMessageWithStringAndParamsUsingGlobalSwitch()
        {
            TraceSwitch traceSwitch = new TraceSwitch(
                "CreateSqlScripterDiagnosticsInstanceWithGlobalTraceSwitch",
                "TraceSwitch for CreateSqlScripterDiagnosticsInstanceWithGlobalTraceSwitch unit test"
                );

            traceSwitch.Level = TraceLevel.Verbose;

            SqlScripterDiagnostics s = new SqlScripterDiagnostics(
                traceSwitch
                );


            SqlScripterDiagnostics.Log(
                TraceLevel.Info,
                "LogMessageWithString:Info:{0}",
                DateTime.Now.ToString()
                );
        }
    }
}
